import json
import time, pytest, allure, pymysql
import requests

urlData = 'http://192.168.1.211:8080'
urlData_212 = 'http://192.168.1.212:8080'
ucAp = 'http://192.168.1.206:8808'
mock_url = 'https://xkiwqblq-yodo1.mock.coding.io'
mock_url_2 = "https://p4elnpr6-yodo1.mock.coding.io"
dev_url = "http://ais-backend.cb64eaf4841914d918c93a30369d6bbc6.cn-beijing.alicontainer.com/ais-backend"
dev_url_2 = "http://ais-frontend.cb64eaf4841914d918c93a30369d6bbc6.cn-beijing.alicontainer.com/ais"
dev_web_url = "http://space-test.yodo1.com/admin-api"

def random_time():
    ticks = time.time()
    # print(int(ticks))
    return int(ticks)

user_token = ""

# @allure.step("校验接口回参")
# def printCode(rpb):
#     # r = requests.post(url, data)
#     print("接口返回状态：", rpb)
#     print("error_code：", rpb.json())
#     print("error_code：", rpb.json()["error_code"])
#
#     Idata = rpb.json()["error_code"]
#     assert Idata == 0 or Idata == "0"

# if Idata == 0:
#     print("\033[1;32m 接口通过!，返回的是int \033[0m")
#     print("----------------------------")
# elif Idata == "0":
#     print("\033[1;32m 接口通过!\033[0m，\033[1;35m 返回的是string！ \033[0m")
#     print("----------------------------")
# else:
#     print("\033[1;35m 接口错误! \033[0m")
#     print("----------------------------")


@allure.step("mock_get_校验接口code")
def get_printCode(rpb):
    print("接口返回状态：", rpb)
    print("code：", rpb.json())
    print("code：", rpb.json()["code"])
    code = rpb.json()["code"]
    assert code == 3


@allure.step("mock_post_校验接口code")
def post_printCode(rpb):
    print("接口返回状态：", rpb)
    print("code：", rpb.json())
    print("code：", rpb.json()["code"])
    code = rpb.json()["code"]
    assert code == 3


@allure.step("dev_get_校验接口code")
def get_printDev(rpb):
    print("接口返回状态：", rpb)
    print("code：", rpb.json())
    print("code：", json.dumps(rpb.json(), indent=2, ensure_ascii=False))
    print("code：", rpb.json()["success"])
    code = rpb.json()["success"]
    assert code is True


@allure.step("dev_post_校验接口code")
def post_printDev(rpb):
    print("接口返回状态：", rpb)
    print("code：", rpb.json())
    print("code：", json.dumps(rpb.json(), indent=2, ensure_ascii=False))
    print("code：", rpb.json()["success"])
    code = rpb.json()["success"]
    assert code is True


@allure.step("调用mockheaders")
def call_header(call_number):
    if call_number == "get_s":
        get_header = {
            "X-Coding-Mock-Token": "in82hqsvubfm6cmyrdoes44z2htlqqec"
        }

        return get_header
    else:
        post_header = {
            "X-Coding-Mock-Token": "in82hqsvubfm6cmyrdoes44z2htlqqec",
            "content-type": "application/json"
        }
        return post_header


# if __name__ == '__main__':
#     pass

s = call_header("get_s")
print(s)


import random, string
#生成5开头的字母数字的23位序列
num = string.ascii_letters + string.digits
test_uid = "5" + "".join(random.sample(num, 23))
print("5" + "".join(random.sample(num, 23)))